<template>
	<view class="mainpadding">
		<view class="margin_top6 sanshier fonweight">我的昵称</view>
		<view class="flexbetween xiahuaxian margin_top">
			<input type="text" placeholder="请输入您的昵称" v-model="nickname">
			<u-icon name="close-circle-fill" color="#CCCCCC" size="20" @click="nickname=''"></u-icon>
		</view>
		<view class="margin_top2 strongtext xiaohui">{{nickname.length}}/10</view>
		<view class="gudingdb ffffff mainpadding">
			<view class="bigbtn" @click="save()">提交</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				nickname: ""
			}
		},
		onLoad(opt) {
			this.nickname = opt.name
		},
		methods: {
			save() {
				if (this.nickname == "") {
					httpRequest.toast("请输入昵称")
					return false
				}
				if (this.nickname.length > 10) {
					httpRequest.toast("名称过长！")
					return false
				}
				httpRequest.request('/api/user/profile', 'GET', {
					nickname: this.nickname
				}).then(res => {
					if (res.code == 1) {
						uni.$emit("editname", this.nickname)
						uni.navigateBack(1)
					}else{
						httpRequest.toast(res.msg)
					}
				})
			}
		}
	}
</script>

<style>

</style>